package request

import (
	"gin_server/internal/model"
	"time"
)

// UserCreateRequest 用于创建用户的请求结构体
type UserCreateRequest struct {
	UserName    string               `json:"user_name" binding:"required,max=48" `                  // 用户名
	UserAvatar  string               `json:"user_avatar" binding:"required,max=120" `               // 用户头像
	Sex         model.SexType        `json:"sex" binding:"required,oneof=man woman unknown" `       // 性别
	Birthday    *time.Time           `json:"birthday" binding:"omitempty" `                         // 生日
	Account     string               `json:"account" binding:"required,max=48" `                    // 账号
	SelfAccount string               `json:"self_account" binding:"required,max=48" `               // 自定义账号
	Password    string               `json:"password" binding:"required,max=64" `                   // 用户密码
	UserRole    model.UserRoleType   `json:"user_role" binding:"required,oneof=default admin vip" ` // 用户权限
	UserStatus  model.UserStatusType `json:"user_status" binding:"required,oneof=enable disable" `  // 用户状态
}

// UserUpdateRequest 用于更新用户的请求结构体
type UserUpdateRequest struct {
	UserName    *string               `json:"user_name" binding:"omitempty,max=48" `                  // 用户名
	UserAvatar  *string               `json:"user_avatar" binding:"omitempty,max=120" `               // 用户头像
	Sex         *model.SexType        `json:"sex" binding:"omitempty,oneof=man woman unknown" `       // 性别
	Birthday    *time.Time            `json:"birthday" binding:"omitempty,datetime" `                 // 生日
	Account     *string               `json:"account" binding:"omitempty,max=48" `                    // 账号
	SelfAccount *string               `json:"self_account" binding:"omitempty,max=64" `               // 自定义账号
	Password    *string               `json:"password" binding:"omitempty,max=64" `                   // 用户密码
	UserRole    *model.UserRoleType   `json:"user_role" binding:"omitempty,oneof=default admin vip" ` // 用户权限
	UserStatus  *model.UserStatusType `json:"user_status" binding:"omitempty,oneof=enable disable" `  // 用户状态
}

// UserQueryRequest 用于查询用户的请求结构体
type UserQueryRequest struct {
	Current     int                   `form:"current" binding:"required" default:"1"`
	PageSize    int                   `form:"pageSize" binding:"required" default:"10"`
	UserName    *string               `form:"user_name" binding:"omitempty,max=48" `                  // 用户名
	Sex         *model.SexType        `form:"sex" binding:"omitempty,oneof=man woman unknown" `       // 性别
	Birthday    *time.Time            `form:"birthday" binding:"omitempty,datetime" `                 // 生日
	Age         *int64                `form:"age" binding:"omitempty" `                               // 年龄
	Account     *string               `form:"account" binding:"omitempty,max=48" `                    // 账号
	SelfAccount *string               `form:"self_account" binding:"omitempty,max=48" `               // 自定义账号
	UserRole    *model.UserRoleType   `form:"user_role" binding:"omitempty,oneof=default admin vip" ` // 用户权限
	Password    *string               `form:"password" binding:"omitempty,max=64" `                   // 用户密码
	UserStatus  *model.UserStatusType `form:"user_status" binding:"omitempty,oneof=enable disable" `  // 用户状态

}

// ToModel 将请求结构体转换为模型结构体
func (req *UserCreateRequest) ToModel() *model.User {
	return &model.User{
		UserName:    req.UserName,
		UserAvatar:  req.UserAvatar,
		Sex:         req.Sex,
		Birthday:    req.Birthday,
		Account:     req.Account,
		SelfAccount: req.SelfAccount,
		Password:    req.Password,
		UserRole:    req.UserRole,
		UserStatus:  req.UserStatus,
	}
}

// LoginRequest 登录请求结构体
type LoginRequest struct {
	Account  string `json:"account" binding:"required"`  // 账号（可以是self_account或account）
	Password string `json:"password" binding:"required"` // 密码
}

// LoginRequest 登录请求
type RegisterRequest struct {
	Account  string `json:"account" binding:"required,email"`    // 账号
	Password string `json:"password" binding:"required,max=64"`  // 用户密码
	Code     string `json:"code" binding:"required,min=6,max=6"` // 验证码
}

// RefreshTokenRequest 刷新token请求结构体
type RefreshTokenRequest struct {
	RefreshToken string `json:"refresh_token" binding:"required,jwt"` // 刷新token
}
